<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<?php
require_once dirname(__FILE__) . '/data.inc.php';
require_once dirname(__FILE__) . '/../../../metadata.php';
require_once dirname(__FILE__) . '/../../../config.php';
$order_id = $_GET['oid'];
$payment_id = $_GET['pid'];
$order_no = $_GET['ono'];
$order_total = $_GET['ot'];
$order_shiptotal = $_GET['ost'];
$data = getData($payment_id, 1);
$link = 'http://' . DOMAIN . PATH;
?>
<link href="ecommerce/payments/<?php echo $folder; ?>/assets/default.css" rel="stylesheet" type="text/css" />
<style>
table.table {
  border: 1px solid #dddddd;
}

.close {
  font-size: 16px;
  font-family: Trebuchet MS;
  font-weight: 600;
  color: #ff8800;
}

.pay_tip1 {
  font-size: 10px;
  font-family: Trebuchet MS;
  font-weight: 400;
  padding-left: 10px;
  text-align: left;
  vertical-align: bottom;
}

.pay_tip2 {
  font-size: 10px;
  font-family: Trebuchet MS;
  font-weight: 600;
  padding-left: 10px;
  text-align: left;
  vertical-align: bottom;
}
</style>

</head>

<body>

<div align="center" valign="middle">
<table width="<?php echo $data->width; ?>" height="<?php echo $data->height; ?>" class="table">
  <tr>
    <td align="center" style="text-align: right; font-weight: bold; width: 55%;">Pay By Paypal</td>
    <td style="text-align: left;padding-left: 10px;"><img src="ecommerce/payments/<?php echo $folder; ?>/assets/p.png"></img></td>
  </tr>
  <tr>
    <td align="center" valign="middle" height="100%" colSpan=2>
      <form id="paypal_form" method="post" action="" target="_blank">
        <input type="hidden" name="cmd" value="_xclick"></input>
        <input type="hidden" name="business" value="<?php echo $data->payment->account; ?>"></input>
        <input type="hidden" name="item_name" value="<?php echo $order_no; ?>"></input> 
        <input type="hidden" name="item_number" value=""></input>
        <input type="hidden" name="amount" value="<?php echo $order_total; ?>"></input>
        <input type="hidden" name="currency_code" value="<?php echo $data->payment->currency_code; ?>"></input> 
        <input type="hidden" name="custom" value="<?php echo $data->payment->is_formal; ?>"></input>
        <input type="hidden" name="charset" value="utf-8"></input> 
        <input type="hidden" name="no_shipping" value="1"></input> 
        <input type="hidden" name="no_note" value="1"></input> 
        <input type="hidden" name="notify_url" value="<?php echo $link; ?>ecommerce/payments/<?php echo $folder; ?>/ipn.php"></input>
        <input type="hidden" name="return" value="<?php echo $link . $data->payment->return_link . '&act=order'; ?>" /></input>
        <input type="hidden" name="cancel_return" value="<?php echo $link . $data->payment->cancel_link; ?>"></input>
        <input type="image" src="ecommerce/payments/<?php echo $folder; ?>/assets/paypal.png" name="submit" alt="Use PayPal Payment" id="paypal" onclick="showchoise();"></input>
      </form>
    </td>
  </tr>
</table>
</div>

<script type="text/javascript">
  function showchoise() {
    var btn = document.getElementById('paypal');
    var form = document.getElementById('paypal_form');
    var is_formal = "<?php echo $data->payment->is_formal; ?>";
    btn.disabled = true;
    if (is_formal == 0) {
      form.action = 'https://www.sandbox.paypal.com/cgi-bin/webscr';
    } else {
      form.action = 'https://www.paypal.com/cgi-bin/webscr';
    }
    
    form.submit();
    
    var _self = this;
    var size = DOMUtils_xDocSize();
    this._bg = document.createElement('div');
    this._bg.style.width = size.w + 'px';
    this._bg.style.height = size.h + 'px';
    this._bg.style.top = '0px';
    this._bg.style.left = '0px';
    this._bg.style.position = 'absolute';
    this._bg.style.backgroundImage = 'url(ecommerce/payments/<?php echo $folder;?>/assets/bb.png)';
    parent.parent.document.body.appendChild(this._bg);

    this._position = [(size.w - 500) / 2, (size.h - 220) / 2];
    this._container = document.createElement('div');
    this._container.style.position = 'absolute';
    this._container.style.border = '4px solid #767576';
    this._container.style.backgroundColor = '#fff';
    this._container.style.top = this._position[1] + 'px';
    this._container.style.left = this._position[0] + 'px';
    this._bg.appendChild(this._container);

    var table = document.createElement('table');
    this._container.appendChild(table);
    table.style.width = '500px';
    table.style.height = '200px';
    table.cellPadding = 0;
    table.cellSpacing = 0;
    var tr = table.insertRow(-1);
    var td = tr.insertCell(-1);
    td.style.height = '10px';
    td.style.fontSize = '15px';
    td.style.fontFamily = 'Trebuchet MS';
    td.style.fontWeight = '600';
    td.style.paddingLeft = '10px';
    td.align = 'left';
    td.vAlign = 'bottom';
    td.style.borderBottom = 'solid 1px #ccc';
    td.style.paddingBottom = '10px';
    td.appendChild(document.createTextNode('Paying My Order...'));
    
    var td = tr.insertCell(-1);
    td.align = 'right';
    td.vAlign = 'bottom';
    td.style.paddingRight = '15px';
    td.style.height = '30px';
    td.style.borderBottom = 'solid 1px #ccc';
    td.style.paddingBottom = '10px';
    
    
    var tr = table.insertRow(-1);
    var td = tr.insertCell(-1);
    td.colSpan = 2;
    td.style.height = '10px';
    td.style.fontSize = '15px';
    td.style.fontFamily = 'Trebuchet MS';
    td.style.fontWeight = '400';
    td.style.paddingLeft = '10px';
    td.align = 'left';
    td.vAlign = 'middle';
    td.style.paddingTop = '10px';
    td.appendChild(document.createTextNode('Did you complete payment successfully?'));

    var tr = table.insertRow(-1);
    var td = tr.insertCell(-1);
    td.colSpan = 2;
    td.style.width = '50%';
    td.style.height = '80px';
    td.style.textAlign = 'center';
    td.style.paddingRight = '15px';
    td.vAlign = 'middle';
    td.style.fontSize = '14px';
    td.style.fontFamily = 'Trebuchet MS';
    td.style.fontWeight = '600';
    elm = imgBtn('Yes', 'ecommerce/payments/<?php echo $folder; ?>/assets/s.png');
    elm.style.width = '100px';
    elm.onclick = function() {parent.parent.location.href = '<?php echo $link . $data->payment->return_link . '&act=order'; ?>'};
    td.appendChild(elm);
    td.style.width = '50%';
    td.style.height = '80px';
    td.align = 'left';
    td.style.paddingRight = '15px';
    td.vAlign = 'middle';
    td.style.fontSize = '14px';
    td.style.fontFamily = 'Trebuchet MS';
    td.style.fontWeight = '600';
    elm = imgBtn('No', 'ecommerce/payments/<?php echo $folder; ?>/assets/f.png');
    elm.style.width = '100px';
    elm.onclick = function() {parent.parent.location.href = '<?php echo $link . $data->payment->return_link . '&act=order'; ?>'};
    td.appendChild(elm);
  };

  function imgBtn(text, imgPath) {
    var table, tr, td, span, elm;
    span = document.createElement('div');
    span.style.background = 'url(image/btn/bg.png) repeat';
    span.style.borderBottom = '2px solid #666666';
    span.style.borderRight = '2px solid #666666';
    span.style.borderLeft = '2px solid #bbbbbb';
    span.style.borderTop = '2px solid #bbbbbb';
    span.style.padding = '2px 5px';
    span.style.marginLeft = '5px';
    span.style.fontFamily = 'Lucida Sans Unicode';
    span.style.fontWeight = 'bold';
    span.style.cursor = 'pointer';
    span.style.fontSize = '14px';
    span.style.display = 'inline-block';
    table = document.createElement('table');
    tr = table.insertRow(-1);
    td = tr.insertCell(-1);
    elm = document.createElement('img');
    elm.src = imgPath;
    td.appendChild(elm);
    td = tr.insertCell(-1);
    td.appendChild(document.createTextNode(text));
    span.appendChild(table);
    return span;
  };
  
  function DOMUtils_findPos(elem) {
    var curleft = 0, curtop = 0;
    if (elem.offsetParent) {
      curleft = elem.offsetLeft;
      curtop = elem.offsetTop;
      while ((elem = elem.offsetParent)) {
        curleft += elem.offsetLeft;
        curtop += elem.offsetTop;
      }
    }
    return [ curleft, curtop ];
  };


  function DOMUtils_xDocSize() {
    var b = parent.parent.document.body, e = parent.parent.document.documentElement;
    var esw = 0, eow = 0, bsw = 0, bow = 0, esh = 0, eoh = 0, bsh = 0, boh = 0;
    if (e) {
      esw = e.scrollWidth;
      eow = e.offsetWidth;
      esh = e.scrollHeight;
      eoh = e.offsetHeight;
    }
    if (b) {
      bsw = b.scrollWidth;
      bow = b.offsetWidth;
      bsh = b.scrollHeight;
      boh = b.offsetHeight;
    }
    return {
      w : Math.max(esw, eow, bsw, bow),
      h : Math.max(esh, eoh, bsh, boh)
    };
  };
</script>
</body>
</html>
